package util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import protocal.DataPackage;
import data.User;

public class MessageUtil {
	
	public static String buildMessage(DataPackage dataPackage){
		Date date = new Date( dataPackage.getTime());
		DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
		String time ="["+User.name+" Online "+dateFormat.format(date)+"]";
		
		String toname = dataPackage.getToName();
		if (toname.equals("\\")) {
			toname = "all";
		}
		if (toname.equals(User.name)) {
			toname = "you";
		}
		
		return time+"    "+dataPackage.getFromeName()+" to "+toname+":"+dataPackage.getMessageData()+"\n";
	}
	
	public static String buildShake(DataPackage dataPackage){
		Date date = new Date( dataPackage.getTime());
		DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
		String time ="["+User.name+" Online "+dateFormat.format(date)+"]";
		if (dataPackage.getToName().equals("\\")) {
			return time+"    "+dataPackage.getFromeName()+" shake all!\n";
		}
		return time+"    "+dataPackage.getFromeName()+" shake you!\n";
	}
	
	public static String buildFromeShake(DataPackage dataPackage){
		Date date = new Date( dataPackage.getTime());
		DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
		String time ="["+User.name+" Online "+dateFormat.format(date)+"]";
		if (dataPackage.getToName().equals("\\")) {
			return time+"    you shake all!\n";
		}
		return time+"    you shake "+dataPackage.getToName()+"!\n";
	}

}
